from typing import *


class Solution:

    def maxAlternatingSum(self, nums: List[int]) -> int:
        a = s = 0
        for n in nums:
            a, s = max(a, s + n), max(s, a - n)
        return max(a, s)
